#ifndef CONSOLE_H
#define CONSOLE_H

#include "MudBath.h"


#include "utils/EditString.h"

#include "script/Interpreter.h"

#define CONSOLE_LINE_LENGTH 85
#define CONSOLE_LINE_COUNT 15
#define CONSOLE_MAX_LINES 32000
#define CONSOLE_MAX_HISTORY 64


class Console :
//public Ogre::Singleton<Console>,
	public Ogre::FrameListener, Ogre::LogListener
{
public:
	Console();
	virtual ~Console();
	void init(Ogre::Root *root);
//		void init(Ogre::Root *root, lua_State *L );
	static Console* getSingletonPtr();

	void messageLogged( const Ogre::String& message, Ogre::LogMessageLevel lml, bool maskDebug, const Ogre::String &logName );
	void print( std::string text );
	void addToHistory( const std::string& cmd );

	bool injectKeyPress( const OIS::KeyEvent &evt );

	bool frameStarted(const Ogre::FrameEvent &evt);
	bool frameEnded(const Ogre::FrameEvent &evt);

	void setVisible(bool fVisible);
	inline bool isVisible() { return visible; }

	int                     start_line;
	bool                    visible;
	bool                    textChanged;
	float                   height;
	bool                    cursor_blink;
	float                   cursor_blinkTime;
	
	bool					isModifierDown;
	
	std::list<std::string>  lines;
	std::list<std::string>  history;
	std::list<std::string>::iterator    history_line;


	EditString              editline;

	inline Interpreter* getInterpreter() { return mInterp; }
	inline void setInterpreter(Interpreter* i)
	{
		mInterp = i;
		print( mInterp->getOutput() );
		mInterp->clearOutput();
	}

protected:
	Interpreter				*mInterp;
	Ogre::Root              *root;
	Ogre::Overlay           *overlay;
	Ogre::OverlayContainer  *panel;
	Ogre::OverlayElement    *textbox;

	static Console* mConsole;
};
#endif //CONSOLE_H
